// pages/recommend/recommend.js
const URL = "https://v.cjveg.com/api";
import { getVideo, getBannerList, getCommentList,getNewVideoList, getHotVideoList } from "../../utils/api.js";
import { tsFormatTime, retTimeInterval } from "../../utils/util.js";
var aa = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
  },
  getData: function (Type) {
    // 请求最新视频
    getNewVideoList(6, 1, (data) => {
      this.setData({
        newList: data
      })
    })
    // 请求最热视频
    getHotVideoList(6, (data) => {
      this.setData({
        hotList: data
      });
    })
    // 请求banner
    getBannerList(3, (data) => {
      // console.log(data)
      this.setData({
        bannerList: data
      });
      if (Type) {
        // 隐藏导航栏加载框
        wx.hideNavigationBarLoading();
        // 停止下拉动作
        wx.stopPullDownRefresh();
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
  
    try {
      var value = wx.getStorageSync('spid')
      wx.setStorage({
        key: 'cs',
        data: aa,
      })
      if (value.length != 0) {
        console.log('haha')
         for(var i in value){
           wx.request({
             url: URL + '/getvideodetail?',
             data: {
               id: value[i]
             },
             success: function (res) {
               console.log(res.data)
               aa.push(res.data)
               that.setData({
                 mv: aa
               })
               console.log(that.data.mv)
             }
           })
         }
        aa = [];
       
      }
    } catch (e) {
      // Do something when catch error
    }
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.hideLoading()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.getData(true);
  }
})